package com.com.knowledgepaymentmanagementsystem.controller.marketing;

import com.com.knowledgepaymentmanagementsystem.pojo.marketing.Limit;
import com.com.knowledgepaymentmanagementsystem.service.marketing.LimitService;
import com.com.knowledgepaymentmanagementsystem.utils.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 张攀
 * @version 1.0
 * @description: TODO
 * @date 2025/9/23 上午11:04
 */
@Api(tags = "营销管理")
@RestController
@CrossOrigin
@RequestMapping("/limit")
public class LimitController {
    @Autowired
    private LimitService limitService;

    @ApiOperation(value = "查询营销数据",httpMethod = "POST",notes = "查询营销数据")
    @PostMapping("/find")
    public ResultUtil<List<Limit>> getLimit(@RequestBody Limit limit){
        List<Limit> limits = limitService.getLimit(limit);
        try {
            return new  ResultUtil<>(200,"查询成功",limits);
        } catch (Exception e) {
            e.printStackTrace();
            return new  ResultUtil<>(200,"查询失败");

        }
    }

    @ApiOperation(value = "新增营销数据",httpMethod = "POST",notes = "新增营销数据")
    @PostMapping("insert")
    public ResultUtil insertLimit(@RequestBody Limit limit){
        try {
            return new ResultUtil<>(200,"新增成功",limitService.insertLimit(limit));
        } catch (Exception e) {
            e.printStackTrace();
            return new ResultUtil<>(500,"新增失败");
        }
    }

    @ApiOperation(value = "修改营销数据",httpMethod = "PUT",notes = "修改营销数据")
    @PutMapping("/update")
    public ResultUtil updateLimit(@RequestBody Limit limit){

        limitService.updateLimit(limit);
        try {
            return new ResultUtil(200,"修改成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new ResultUtil<>(500,"修改失败");

        }
    }

    @ApiOperation(value = "删除营销数据",httpMethod = "DELETE",notes = "删除营销数据")
    @DeleteMapping("/delete")
    public ResultUtil deleteLimit(Integer id){
        limitService.deleteLimit(id);
        try {
            return new ResultUtil(200,"删除成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new ResultUtil<>(500,"删除失败");

        }
    }
}
